/**
 * 将对象数组的key转换为小写
 * @param arr 
 */
export function lowerKeyForArray(arr: object[]) {
    return arr.map(obj => {  
        const newObj = {};  
        for (let key in obj) {  
          const lowerCaseKey = key.toLowerCase();  
          newObj[lowerCaseKey] = obj[key];  
        }  
        return newObj;  
      })
}

/**
 * 将源对象中的key与目标对象中的key进行匹配，将源对象中的值赋值给目标对象
 * @param originObj 
 * @param targetObj 
 */
export function objAssignmentToObj(originObj: object, targetObj: object) {
    for (let key in originObj) {
      if(targetObj.hasOwnProperty(key)) {
        targetObj[key] = originObj[key]
      }
    }
}

/**
 * 字节单位转换
 * @param bytes
 * @returns {string}
 */
export function bytesToSize(bytes) {
  bytes = Number(bytes) 
  if (bytes === 0) return "0 B";
  var k = 1024,
    sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
    i = Math.floor(Math.log(bytes) / Math.log(k));

  return (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
}